import {Observable} from 'rxjs/Rx';
import {FormControl} from '@angular/forms';
import {Router} from '@angular/router';
import {Component, OnInit} from '@angular/core';
import {Stock, StockService} from '../stock.service';
import 'rxjs/Rx';

@Component({
  selector: 'app-stock-manger',
  templateUrl: './stock-manger.component.html',
  styleUrls: ['./stock-manger.component.css']
})
export class StockMangerComponent implements OnInit {

  public stocks: Observable<Stock[]>;

  constructor(private router: Router, private stockService: StockService) {
  }

  ngOnInit() {
    this.stocks = this.stockService.getStocks();
    this.stockService.searchEvent.subscribe(
      params=>this.stocks = this.stockService.search(params)
    )
  }

  update(stock: Stock) {
    this.router.navigateByUrl('/stock/' + stock.id);
  }
}

